package com.gears_software.sxdc.dccx.ui.activity;

import android.app.Activity;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gears_software.sxdc.dccx.R;
import com.gears_software.sxdc.dccx.application.DCCXApplication;
import com.gears_software.sxdc.dccx.data.adapter.LiuShuiListAdapter;
import com.gears_software.sxdc.dccx.data.finder.IBankFinder;
import com.gears_software.sxdc.dccx.data.model.ResultModel;
import com.gears_software.sxdc.dccx.data.model.TransactionRecord;
import com.gears_software.sxdc.dccx.ui.util.MaterialDialogProgress;
import com.sdsmdg.tastytoast.TastyToast;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.App;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.rest.spring.annotations.RestService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import qiu.niorgai.StatusBarCompat;

/**
 * Created by SunMuran on 2017/8/4.
 */
@EActivity(R.layout.activity_jiaoyi_liushui)
public class JiaoYiLiuShuiActivity extends Activity {
    @App
    DCCXApplication app;
    @ViewById
    TextView actionbar_title;
    @ViewById
    TextView back_icon;
    @ViewById
    TextView right_icon;
    @ViewById
    ListView lv_liushui;
    @ViewById
    RelativeLayout re_wu;
    @ViewById
    TextView txt_nodata_icon;
    @RestService
    IBankFinder iBankFinder;
    LiuShuiListAdapter adapter;
    List<TransactionRecord> list = new ArrayList<>();
    MaterialDialogProgress progress;

    @AfterViews
    void created() {
        actionbar_title.setText("交易流水");
        initIconfont();
        StatusBarCompat.setStatusBarColor(this, ContextCompat.getColor(this, R.color.colorActionbar));

//        adapter = new LiuShuiListAdapter(this);
//        lv_liushui.setAdapter(adapter);
        progress = new MaterialDialogProgress(this);
        progress.show("正在加载...");
        getTransaction();
    }

    void initIconfont() {
        back_icon.setTypeface(app.iconfont);
        back_icon.setText(R.string.back_icon);
        right_icon.setVisibility(View.GONE);
        txt_nodata_icon.setTypeface(app.iconfont);
    }

    @Click
    void back_icon() {
        finish();
    }

    @Background
    void getTransaction() {
        ResultModel<List<TransactionRecord>> result = iBankFinder.getTransaction();
        showResult(result);
    }

    @UiThread
    void showResult(ResultModel<List<TransactionRecord>> result) {
        if (result != null) {
            if (result.getErrno().equals("0")) {
                list = result.getData();
                if (list != null && list.size() > 0) {
                    re_wu.setVisibility(View.GONE);
                    lv_liushui.setVisibility(View.VISIBLE);
                    adapter = new LiuShuiListAdapter(JiaoYiLiuShuiActivity.this, list);
                    lv_liushui.setAdapter(adapter);
                } else {
                    re_wu.setVisibility(View.VISIBLE);
                    lv_liushui.setVisibility(View.GONE);
                }
            }
        }
        progress.dismiss();
    }
}
